var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModal: false,
    seleNull: null,
    seleNulls: null,
    head: "../../res/imgs.png",
    array: ['是', '否'],
    arrays: [],
    name:'',
    heads:'',
    desc:'',
    price:0,
    kucun:0,
    line_price:0,
    index:0,
    indexs:0
  },


  onLoad: function (options) {
    var store_id = wx.getStorageSync("store_id");
    this.setData({
      store_id:store_id
    })
    this.getSecondsKill();
  },

  getSecondsKill:function(){
    var t = this;
    app.visit("huodong/getSecondsKill", {}, "", function(c) {
      console.log(c)
      if(0 == c.code){
        t.setData({
          arrays:c.data
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  bindPickerChange: function (e) {

    this.setData({
      seleNull: '0',
      index: e.detail.value
    })
  },
  bindPickerChanges: function (e) {

    this.setData({
      seleNulls: '0',
      indexs: e.detail.value
    })
  },
  setLineprice:function(e){
    this.setData({
      line_price:e.detail.value
    })
  },

  setKucun:function(e){
    this.setData({
      kucun:e.detail.value
    })
  },

  setPrice:function(e){
    this.setData({
      price:e.detail.value
    })
  },

  setName:function(e){
    this.setData({
      name:e.detail.value
    })
  },

  setDesc:function(e){
    this.setData({
      desc:e.detail.value
    })
  },
  headimage: function () {
    var _this = this;
    wx.chooseImage({
      count: 1, // 默认9     
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        console.log(res)
        wx.uploadFile({
          url: app.api_url + "/api/index/ups",
          filePath: res.tempFilePaths[0],
          name: "file",
          header: {
            Authorization: wx.getStorageSync("user_id"),
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function(e) {
            console.error("上传回执", e);
            var a;
            0 == (a = "string" == typeof e.data ? JSON.parse(e.data) : e.data).code ? _this.setData({
              head: a.data.url,
              heads: a.data.img
            }) : wx.showToast({
              title: "上传失败"
            });
          },
          complete: function() {}
        });
      }
    })
  },
  bindShowMsg() {
    this.setData({
      select: !this.data.select,
      zz: false,
    })
  },
  tijiao:function(e){
    var t = this;
    app.visit("huodong/setMiaoShaInfos", {
      store_id:t.data.store_id,
      name:t.data.name,
      heads:t.data.heads,
      desc:t.data.desc,
      price:t.data.price,
      kucun:t.data.kucun,
      line_price:t.data.line_price,
      index:t.data.index,
      ms_time:t.data.arrays[t.data.indexs]
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        wx.showToast({
          title: '添加成功',
          icon: 'none',
          success: function () {
            wx.navigateBack();
          }
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },
 
})